<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:h="http://java.sun.com/jsf/html">

<body>
	<ui:composition template="../template.xhtml">

		<ui:define name="right">

		</ui:define>

		<ui:define name="center">


			<h:form enctype="multipart/form-data">

				<h2>Crea Esperimento</h2>
				<p:wizard widgetVar="wiz"
					flowListener="#{experimentController.onFlowProcess}">

					<!-- TAB EXPERIMENT, CREAZIONE SENZA SAMPLE DEL'EXPERIMENT E SALVATAGGIO NEL DATABASE -->

					<p:tab id="experiment" title="#{bundle.CreateExperimentTAB1}">

						<p:panel header="#{bundle.CreateExperimentTitle}">

							<p:growl id="growl" showDetail="true" life="600" />
							<p:messages showDetail="true" autoUpdate="true" />

							<h:panelGrid columns="2" columnClasses="label, value"
								styleClass="grid">

								<h:outputLabel for="serie"
									value="#{bundle.CreateExperimentLabel_series} *" />
								<p:inputText id="serie" required="true"
									label="#{bundle.CreateExperimentTitle_series}"
									value="#{experimentController.experiment.seriesIid}"
									validator="#{experimentController.validateName}">
								</p:inputText>

								<h:outputLabel for="title"
									value="#{bundle.CreateExperimentLabel_title} *" />
								<p:inputText id="title"
									label="#{bundle.CreateExperimentTitle_title}"
									value="#{experimentController.experiment.title}">
								</p:inputText>

								<h:outputLabel for="pubmed"
									value="#{bundle.CreateExperimentLabel_pubmed}" />
								<p:inputText id="pubmed"
									label="#{bundle.CreateExperimentTitle_pubmed}">
								</p:inputText>

								<h:outputLabel for="summary"
									value="#{bundle.CreateExperimentLabel_summary} " />
								<p:inputTextarea id="summary"
									label="#{bundle.CreateExperimentTitle_summary}"
									value="#{experimentController.experiment.summary}">
								</p:inputTextarea>

								<h:outputLabel for="overallDesign"
									value="#{bundle.CreateExperimentLabel_overall} " />
								<p:inputTextarea id="overallDesign"
									label="#{bundle.CreateExperimentTitle_overall}"
									value="#{experimentController.experiment.overallDesign}">
								</p:inputTextarea>

								<h:outputLabel for="type"
									value="#{bundle.CreateExperimentLabel_type} " />
								<p:inputText id="type"
									label="#{bundle.CreateExperimentTitle_type}"
									value="#{experimentController.experiment.type}">
								</p:inputText>
							</h:panelGrid>

						</p:panel>
					</p:tab>

					<!-- TAB SAMPLE, CREAZIONE DEI SAMPLE E SALVATAGGI DIRETTAMEMTE NEL DATABASE -->


					<p:tab id="samples" title="#{bundle.CreateExperimentTAB2}">
						<p:panel header="#{bundle.AddSampleToExperiment}">

							<h:messages errorClass="error" />


							<!-- FIELDSET CREAZIONE SAMPLE -->

							<p:fieldset legend="Crea Campione">


								<p:accordionPanel dynamic="true" cache="true" cellpadding="10"
									activeIndex="">

									<!-- SOTTO-TAB-CAMPIONE, INSERIMENTO INFO TESTO DEL CAMPIONE -->


									<p:tab title="Aggiungi le Info del Campione">

										<h:panelGrid columns="2" columnClasses="label, value">


											<h:outputLabel for="name"
												value="#{bundle.CreateSampleLabel_name} *" />
											<p:inputText id="name" required="true"
												label="#{bundle.CreateSampleTitle_name}"
												value="#{experimentController.sample.name}">
											</p:inputText>

											<h:outputLabel for="t"
												value="${bundle.CreateSampleLabel_title} *" />
											<p:inputText id="t" label="#{bundle.CreateSampleTitle_title}"
												value="#{experimentController.sample.title}">
											</p:inputText>

											<h:outputLabel for="description"
												value="#{bundle.CreateSampleLabel_description} " />
											<p:inputTextarea id="description"
												label="#{bundle.CreateSampleTitle_description}"
												value="#{experimentController.sample.description}">
											</p:inputTextarea>

											<h:outputLabel for="dataProcessing"
												value="#{bundle.CreateSampleLabel_dataPreprocessing} " />
											<p:inputText id="dataProcessing"
												label="#{bundle.CreateSampleTitle_dataPreprocessing}"
												value="#{experimentController.sample.dataPreprocessing}">
											</p:inputText>

											<h:outputLabel for="obsservationFile"
												value="#{bundle.CreateSampleLabel_observationFile} " />
											<p:inputTextarea id="obsservationFile"
												label="#{bundle.CreateSampleTitle_observationFile}"
												value="#{experimentController.sample.observationFile}">
											</p:inputTextarea>


											<h:outputLabel for="tip"
												value="#{bundle.CreateSampleLabel_type} *" />
											<p:selectOneMenu id="tip"
												value="#{experimentController.sample.sampleTypeId}"
												required="true">
												<f:selectItems value="#{experimentController.sampleTypes}"
													var="n" itemLabel="#{n.name}" itemValue="#{n.id}" />
											</p:selectOneMenu>

											<h:outputLabel for="supplementaryDataFile"
												value="#{bundle.CreateSampleLabel_suppDataFile}  " />
											<p:inputText id="supplementaryDataFile"
												label="#{bundle.CreateSampleTitle_suppDataFile}"
												value="#{experimentController.sample.supplementaryDataFile}">
											</p:inputText>

											<h:outputLabel for="treatmentProtocol"
												value="#{bundle.CreateSampleLabel_treatmentProtocol} " />
											<p:inputText id="treatmentProtocol"
												label="#{bundle.CreateSampleTitle_treatmentProtocol}"
												value="#{experimentController.sample.treatmentProtocol}">
											</p:inputText>

											<h:outputLabel for="observationFile"
												value="#{bundle.CreateSampleLabel_observationFile} " />
											<p:inputText id="observationFile"
												label="#{bundle.CreateExperimentTitle_type}"
												value="#{experimentController.sample.observationFile}">
											</p:inputText>
										</h:panelGrid>
									</p:tab>

									<!-- SOTTO-TAB-CAMPIONE, SCELTA DELLA PIATTAFORMA -->

									<p:tab title="Seleziona la piattaforma">


										<p:dataTable id="pl" var="p"
											value="#{experimentController.platformList}" rowKey="#{p.id}"
											selection="#{experimentController.platform}"
											selectionMode="single" rendered="true">

											<f:facet name="header"> Click "View" button after selecting a row to see details </f:facet>

											<p:column headerText="#{bundle.CreatePlatformTitle_title}">
												<h:outputText value="#{p.title}" />
											</p:column>


											<p:column
												headerText="#{bundle.CreatePlatformTitle_accessionName}">
												<h:outputText value="#{p.accessionName}" />
											</p:column>

											<p:column
												headerText="#{bundle.CreatePlatformTitle_organismName}">
												<h:outputText value="#{p.organism.name}" />
											</p:column>

										</p:dataTable>
										<h:panelGrid columns="2" styleClass="grid">
											<h:outputLabel for="plName"
												value="#{bundle.ImportSelectedFileLabe_Name} *" />
											<p:inputText id="selectedPlatform"
												value="#{experimentController.platform.accessionName}"
												readonly="true"></p:inputText>

										</h:panelGrid>
										<p:commandButton value="Select" image="ui-icon ui-icon-search"
											action="#{experimentController.setSampleWithPlatSelected}"
											actionListener="#{experimentController.displayLocation}"
											update="selectedPlatform">
										</p:commandButton>



									</p:tab>

									<!-- SOTTO-TAB-CAMPIONE, INSERIMENTO FILE DEL CAMPIONE -->

									<p:tab title="Aggiungi il file del campione">
										<h:panelGrid columns="2" cellpadding="10">
											<h:outputText value="Aggiungi il file del campione *" />
											<p:fileUpload
												fileUploadListener="#{experimentController.handleFileUpload}"
												mode="advanced" update="messages" sizeLimit="100000000"
												allowTypes="/(\.|\/)(soft|SOFT|txt)$/"
												value="#{platformController.filePath}" rendered="true" />
										</h:panelGrid>
									</p:tab>
								</p:accordionPanel>
								<p:commandButton
									style="float:right; margin-top:20px; position absolute;"
									id="submit" value="Salva Campione" ajax="false"
									action="#{experimentController.addSampleToList}">

								</p:commandButton>

							</p:fieldset>

						</p:panel>

					</p:tab>

					<!-- TAB RESOCONTO INFORMAZIONI INSERITE DI EXPERIMENT CON I RELATIVI CAMPIONI -->
					<p:tab id="confirm" title="#{bundle.CreateExperimentTAB3}">

						<p:panel header="Conferma dati">


							<h:panelGrid columns="2" columnClasses="label, value"
								styleClass="grid">



								<h:outputLabel value="Name: " />
								<h:outputText styleClass="outputLabel"
									value="#{experimentController.experiment.seriesIid}"
									validator="#{platformController.validateName}" />

								<h:outputLabel value="Titolo: " />
								<h:outputText styleClass="outputLabel"
									value="#{experimentController.experiment.title}" />

								<h:outputText value="Pubmed: " />
								<h:outputText styleClass="outputLabel"
									value="#{experimentController.experiment.pubmedId}" />

								<h:outputText value="Overall Design: " />
								<h:outputText styleClass="outputLabel"
									value="#{experimentController.experiment.overallDesign}" />

								<h:outputText value="Tipo Esperimento: " />
								<h:outputLabel styleClass="outputLabel"
									value="#{experimentController.experiment.type}" />



								<h:outputText value="Campioni: " />
								<p:dataTable id="delsample" var="s"
									value="#{experimentController.samples}"
									emptyMessage="Non ci sono campioni: Non è possibile creare un esperimento senza Campioni">

									<p:column headerText="#{bundle.CreateExperimentTitle_name}">
										<h:outputText value="#{s.name}" />
									</p:column>

									<p:column headerText="#{bundle.CreateExperimentTitle_platform}">
										<h:outputText value="#{s.platformId}" />
									</p:column>



									<p:column style="width:100px">
										<h:panelGrid columns="1" styleClass="actions" cellpadding="2">


											<p:commandButton oncomplete="confirmation.show()"
												image="ui-icon ui-icon-close" title="Delete">
												<f:setPropertyActionListener value="#{s}"
													target="#{experimentController.sample}" />
											</p:commandButton>
										</h:panelGrid>
									</p:column>

								</p:dataTable>

								<p:confirmDialog
									message="Sei sicuro di voler cancellare il campione?"
									width="200" header="Confirm" severity="alert"
									widgetVar="confirmation">

									<p:commandButton value="Si" update="delsample"
										action="#{experimentController.deleteToList}"
										oncomplete="confirmation.hide()" />
									<p:commandButton value="No" onclick="confirmation.hide()"
										type="button" />

								</p:confirmDialog>

							</h:panelGrid>



							<p:commandButton
								style="float:right; margin-top:20px; position absolute;"
								id="sub" value="Salva Esperimento" ajax="false"
								actionListener="#{experimentController.createExperiment}">


							</p:commandButton>

						</p:panel>
					</p:tab>

				</p:wizard>
			</h:form>

		</ui:define>

	</ui:composition>


</body>
</html>